 package com.example.geckohurricanes;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class PostItemActivity extends Activity {

	public String itemName, itemDesc, itemLoc;
	ItemDatabaseHandler db;
	List<Item> items;
	EditText itemNameET, itemDescET, itemLocET;
	private int lostOrFound; //1 == lost, 2 == found
	RadioButton found, lost;
	Button submit, back;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.postitem);
		
		itemNameET = (EditText) findViewById(R.id.itemname);
		itemDescET = (EditText) findViewById(R.id.itemdesc);
		itemLocET = (EditText) findViewById(R.id.itemlocation);
		
		db = new ItemDatabaseHandler(this);
		items = db.getAllItems();
		
		back = (Button) findViewById(R.id.btnback);
		back.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});
		
		lost = (RadioButton) findViewById(R.id.radiolost);
		lost.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				onRadioButtonClick(v);
			}
		});
		
		found = (RadioButton) findViewById(R.id.radiofound);
		found.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				onRadioButtonClick(v);
			}
		});
		
		submit = (Button) findViewById(R.id.btnsubmit);
		submit.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				itemName = itemNameET.getText().toString();
				itemDesc = itemDescET.getText().toString();
				itemLoc = itemLocET.getText().toString();
				Item i = new Item(itemName, itemDesc, itemLoc, lostOrFound);
				db.addItem(i);
				Toast.makeText(getApplicationContext(), "Item Posted", Toast.LENGTH_SHORT).show();
				db.close();
				finish();
			}
		});
		
	}

	public void onRadioButtonClick(View v) {
		lostOrFound = 1;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.post_item, menu);
		return true;
	}

}
